﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Kinect;

namespace KinectDwa.Parsers.Data
{
    public enum HandGestures
    {
        None, // Gesture was not available, default value
        Neutral, // Recognized gesture that does no action beyond possibly movement, Pointing
        A, // Left click, L-shape
        B // Right click, Evul
    }

    public class Hand : Joint
    {
        // Hand gesture variables
        public HandGestures Gesture = HandGestures.None;
        public double GestureAccuracy;
        public List<Dictionary<HandGestures, double>> GestureCollection = new List<Dictionary<HandGestures, double>>();

        // Push gesture variables
        public int? previousPushDepth = null;
        public int pushDecay = 0;
        public bool pushClickPending = true;

        // Extra info on the wrist
        public SkeletonPoint wristVector;
        public bool wristTracked = false;

        // Returns hand's angle as radians
        public double GetAngle()
        {
            if ((!wristTracked) || (!isTracked) || (!MouseInputControl.gestureRotation))
            {
                return Math.PI / 2;
            }

            float dx = vector.X - wristVector.X;
            float dy = vector.Y - wristVector.Y;

            double angle = Math.Atan2(dy, dx);

            if (angle > (2 * Math.PI))
            {
                angle -= 2* Math.PI;
            }
            else if (angle < 0)
            {
                angle += 2* Math.PI;
            }

            return angle;
        }

        // Returns hand's angle converted to degrees
        public double GetAngleAsDegrees()
        {
            if ((!wristTracked) || (!isTracked) || (!MouseInputControl.gestureRotation))
            {
                return 90d;
            }

            return GetAngle() * 180 / Math.PI;
        }
    }
}
